﻿using AuthCenter.API.Application.Command.Role;
using AuthCenter.API.DTOs;
using AuthCenter.Domain.Account;
using AuthCenter.ErrorCode;
using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace AuthCenter.API.Controllers
{
    /// <summary>
    /// 角色控制器
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    [Authorize]
    public class RoleController : ControllerBase
    {
        private readonly IMediator mediator;

        public RoleController(IMediator mediator)
        {
            this.mediator = mediator;
        }
        /// <summary>
        /// 新增角色信息接口
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public Task<APIResult<int>> CreateRole(CreateRoleCommand request)
        {
            return mediator.Send(request);
        }
        /// <summary>
        /// 修改角色信息接口
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public Task<APIResult<int>> UpdateRole (UpdateRoleCommand request)
        {
            return mediator.Send(request);
        }
        /// <summary>
        /// 删除角色信息接口
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]   
        public Task<APIResult<int>> DelRole([FromQuery]DelRoleCommand request)
        {
            return mediator.Send(request);
        }
        /// <summary>
        /// 获取角色信息接口
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<APIResult<List<RoleModel>>> GetRole([FromQuery] GetRoleCommand request)
        {
            return mediator.Send(request);
        }
    }
}
